package com.mes.schedule.manager;

import java.util.Set;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.mes.common.util.MMSystemSession;
import com.mes.common.util.SysUtil;
import com.mes.schedule.domain.SOperationTask;
import com.mes.task.domain.OperationTask;

public class MtPrepareTaskControl{
	private final static Log log = LogFactory
	.getLog(MtPrepareTaskControl.class);
	@javax.annotation.Resource
	private ScheduleOperationTaskManager scheduleOperationTaskManager;
	
	private SOperationTask so;
	private Set<OperationTask> ooSet;
	
	private String operType;
	private MMSystemSession systemSession;
	
	public MtPrepareTaskControl(String operType,
			ScheduleOperationTaskManager scheduleOperationTaskManager,
			SOperationTask so, Set<OperationTask> ooSet,MMSystemSession systemSession) {
		super();
		this.operType = operType;
		this.scheduleOperationTaskManager = scheduleOperationTaskManager;
		this.so = so;
		this.ooSet = ooSet; 
		this.systemSession=systemSession;
		
	}

	 
	public void run() {
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
		if (log.isDebugEnabled()) {
			Thread.currentThread().setName("生产准备下发管理线程 ");
		}

		
		try {
//			for(int i=1;i<10;i++)
//			{
//				Thread.sleep(1000);
//			}
			//让线程中也能有session变量
			//必须放在这里，不能够放在构造函数中
			//貌似构造函数还是在主线程中
			SysUtil.systemSessionLocal.set(systemSession);
			if(log.isDebugEnabled())
			{
				log.info(SysUtil.getSessionEmployeeUid());
			}
			
			if(operType.equals("A"))
				scheduleOperationTaskManager.saveOrUpdatePrepareTask(so, ooSet);
				
			else {
				scheduleOperationTaskManager.cancelPrepareTask(so, ooSet);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e);
		}
		
	}

}
